package com.example.chirdrenserver.controller.AdminController;

import com.example.chirdrenserver.Authority.Authority;
import com.example.chirdrenserver.Pojo.dto.SystemDTO;
import com.example.chirdrenserver.Pojo.entity.SystemConfig;
import com.example.chirdrenserver.Service.SystemService;
import com.example.chirdrenserver.Utils.Result;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system")
public class SystemController {
    @Autowired
    SystemService systemService;

    @GetMapping("/list")
    @Authority(authority= "permission:system")
    public Result getSystem() {

        return Result.success(systemService.list());
    }

    @PostMapping("/{id}")
    @Authority(authority= "permission:system")
    public Result updateSystem(@PathVariable Integer id, @RequestBody SystemDTO systemDTO) {
        SystemConfig systemConfig = new SystemConfig();
        BeanUtils.copyProperties(systemDTO, systemConfig);
        systemConfig.setConfigId(id);
        systemService.updateById(systemConfig);
        return Result.success();
    }
}
